﻿using System.Collections.ObjectModel;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ServiceModel.DomainServices.Client;

namespace MedLink2011.Web.Models
{
    /// <summary>
    /// Extensions to provide client side custom validation and data binding to <see cref="Consult_Payment"/>.
    /// </summary>
    public partial class Consult_Payments  
    {

        public bool IsModified
        {
            get
            {
                return EntityState == EntityState.Modified;
            }
        }

        public bool IsNew
        {
            get
            {
                return (EntityState == EntityState.New) ||
                       (EntityState == EntityState.Detached);
            }
        }

        protected override void OnPropertyChanged(PropertyChangedEventArgs e)
        {
            base.OnPropertyChanged(e);

            if (String.CompareOrdinal(e.PropertyName, "EntityState") == 0)
            {
                RaisePropertyChanged("IsNew");
                RaisePropertyChanged("IsModified");
            }
        }

        public bool Validate(ValidationContext validationContext)
        {
            ValidationErrors.Clear();

            IServiceProvider serviceProvider = validationContext;
            IDictionary<object, object> items = null;
            if (validationContext != null)
            {
                items = validationContext.Items;
            }

            ValidationContext vc = new ValidationContext(this, serviceProvider, items);
            ICollection<ValidationResult> validationResults = new List<ValidationResult>();
            if (Validator.TryValidateObject(this, vc, validationResults) == false)
            {
                foreach (ValidationResult error in validationResults)
                {
                    ValidationErrors.Add(error);
                }
                return false;
            }

            return true;
        }
        
        private bool _selected;
        public bool IsSelected
        {
            get
            {
                return _selected;
            }
            set
            {
                _selected = value;
                RaisePropertyChanged("IsSelected");
            }
        }

    }
}

